import os
import signal
import sys
import threading
import time

import keyboard
from keyboard import KeyboardEvent


def callback(event: KeyboardEvent):
    if(event.name == 'left'):
        print('当前值:', count)
    if(event.name == 'ctrl + c'):
        sys.exit()
def exit():
    global stop_flag
    stop_flag = False
    print("=======退出======")
def listen():
    # keyboard.on_press(callback)
    keyboard.add_hotkey('ctrl+c',exit)
    keyboard.wait('1')

def add():
    global count
    while True:
        # print(str(count) + '+1')
        count +=1
        time.sleep(1)
        if stop_flag:
            break

def exit(signum, frame):
    print('You choose to stop me.')
    global stop_flag
    stop_flag = True
    os.exit(0)

if __name__ == '__main__':
   count = 0
   stop_flag = False
   # threading.Thread(target=listen).start()
   t_add = threading.Thread(target=add).start()
   listen()
